package com.kedi.healthcenter.read.dao.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 
 *
 * @author: 	陈辽逊
 * @date: 		2019/7/13 12:32
 */
@Mapper
public interface OldlifeMapper {
		
     /**
	 * 				  	根据id范围床位预约列表
	 * @return			findBedList
	 */
	@Select("SELECT COUNT(bed_id) as total_size,bed_id,oldlife_id,bedNumsber,price,minPrice,maxPrice, "
			+ "`status`,p_user_id,`name`,address,phone,"
			+ "CONVERT (`Introduction`  USING utf8) AS Introduction,"
			+ "praise_points,collection_num,url "
			+ "FROM `bed_oldlife` "
			+ "ORDER BY bed_id ASC "
			+ "LIMIT  #{page},#{limit};")
	List<Map<String, Object>> findBedList(@Param("page")int page,@Param("limit")int limit);		
	
	/**
	 * 					根据minprice和maxprice返回区间价格
	 * @param 			minprice
	 * @param 			maxprice
	 * @return			oldprice
	 */
	@Select("SELECT COUNT(bed_id) as total_size,bed_id,oldlife_id,bedNumsber,price,minPrice,maxPrice,"
			+ "`status`,p_user_id,`name`,address,phone,"
			+ "CONVERT (`Introduction`  USING utf8) AS Introduction,"
			+ "praise_points,collection_num,url "
			+ "FROM `bed_oldlife` "
			+ "where price>(#{minprice}) and price<(#{maxprice})"
			+ "ORDER BY bed_id ASC "
			+ "LIMIT  #{page},#{limit};")
	List<Map<String, Object>> oldprice(@Param("minprice")int minprice,@Param("maxprice")int maxprice,@Param("page")int page,@Param("limit")int limit);
	
	/**
	 * 获取预约床位列表部分信息
	 * @param
	 * @return			返回一个封装的数据对象oldlifepart
	 */
	@Select("SELECT bedNumsber,price,status,p_user_id,name,address " 
			 +"FROM bed_oldlife")
	List<Map<String, Object>> oldlifepart();
	/**
	 * 	获取预约床位详情信息
	 * @param 			oldlifeid
	 * @return			返回一个封装的数据对象oldall
	 */
	@Select("SELECT oldlife_id,bedNumsber,price,minPrice,maxPrice, " 
			 +"`status`,p_user_id,`name`,address,phone, " 
			 +"CONVERT (`Introduction`  USING utf8) AS Introduction, " 
			 +"praise_points,collection_num,url  "  
			 +"FROM bed_oldlife  " 
			 +"WHERE oldlife_id =(#{oldlifeid})")
	Map<String, Object> oldlifeall(@Param("oldlifeid")int oldlifeid);



	/**
	 * 方法实现说明  判断用户在养老上是否点赞
	 * @author      ytw
	 *@param         oldlifeid,puserid
	 * @return
	 * @exception
	 * @date        2019/7/31 10:59
	 */
	@Select("select p_user_id from praise where oldlife_id=#{oldlife_id} and p_user_id=#{p_user_id}")
	Integer  findUserPraise(@Param("oldlife_id")Integer oldlifeid,@Param("p_user_id")Integer puserid);

	/**
	 * 方法实现说明  判断用户在养老上是否收藏
	 * @author      ytw
	 *@param         oldlifeid,puserid
	 * @return
	 * @exception
	 * @date        2019/7/31 10:59
	 */
	@Select("select p_user_id from colection where oldlife_id=#{oldlife_id} and p_user_id=#{p_user_id} ")
	Integer  findUserColection(@Param("oldlife_id")Integer oldlifeid,@Param("p_user_id")Integer puserid);
}
